﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using AlertSystem.Utils;

namespace AlertSystem.Dab
{
    public class DabLoadProvider : ILoadProvider<DataRow>
    {
        protected virtual string ConnectionParamName
        {
            get { throw new NotImplementedException(); }
        }

        protected virtual string QueryParamName
        {
            get { throw new NotImplementedException(); }
        }

        public IEnumerable<DataRow> LoadFrom(object param)
        {
            var loadParams = CheckAndParceParam.GetConnectionAndQuery(param, ConnectionParamName, QueryParamName);

            DataTable table = new DataTable();
            using (SqlConnection conn = new SqlConnection(loadParams.Item1))
            {
                var cmd = conn.CreateCommand();
                cmd.CommandText = loadParams.Item2;
                cmd.CommandType = CommandType.StoredProcedure;
                conn.Open();
                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                ad.Fill(table);
            }

            //dab.SelectLkOrders
            return table.AsEnumerable();
        }



    }
}
